package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.common.VMSystem;
import com.lkd.config.TopicConfig;
import com.lkd.contract.OrderCheck;
import com.lkd.emq.Topic;
import com.lkd.entity.OrderEntity;
import com.lkd.service.OrderService;
import com.lkd.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Topic("$delayed/600/"+TopicConfig.ORDER_CHECK_TOPIC)
public class cancelUselessHandler implements MsgHandler {
    @Autowired
    private OrderService orderService;

    @Override
    public void process(String jsonMsg) throws IOException {
        OrderCheck orderNo = JsonUtil.getByJson(jsonMsg, OrderCheck.class);
        OrderEntity orderEntity = orderService.getByOrderNo(orderNo.getOrderNo());
        Integer payStatus = orderEntity.getPayStatus();
        if(payStatus == 0){
            orderEntity.setStatus(VMSystem.ORDER_STATUS_INVALID);
            orderService.updateById(orderEntity);
        }
    }
}
